package ${packageName}.common.config.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    @Value("${'$'}{${projectName}.system.desc}")
    private String desc;

    @Value("${'$'}{${projectName}.user.author}")
    private String author;

    @Value("${'$'}{${projectName}.user.email}")
    private String email;

    @Value("${'$'}{${projectName}.user.url}:${'$'}{server.port}")
    private String url;

    @Value("${'$'}{swagger.enabled}")
    private Boolean enabled;

    @Value("${'$'}{swagger.system.enabled}")
    private Boolean systemEnabled;

    @Bean(value = "code")
    public Docket code() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(systemEnabled)
                .apiInfo(apiInfo("${remarks}-api",  "1.0"))
                .groupName("${projectName}")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build();
    }






    private ApiInfo apiInfo(String title, String version) {
        return new ApiInfoBuilder()
                .title(title)
                .licenseUrl(url + "/doc.html")
                .license("Knife4j API 接口文档")
                .contact(new Contact(author, url, email))
                .description(desc)
                .version(version)
                .build();
    }
}
